Home > Support > HOWTO List > Accessing Postgresql via JDBC

Accessing Postgresql via JDBC

For PostgreSQL 7.X, in /var/lib/pgsql/data/postgresql.conf set:

tcpip_socket = true

For PostgreSQL 8.X, see
http://www.postgresql.org/docs/8.1/static/runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-SETTINGS

This permits access to postgresql using sockets rather than Linux socket files.

In /var/lib/pgsql/data/pg_hba.conf, uncomment:

host    all         all         127.0.0.1         255.255.255.255   trust

This allows clients on the server to connect to the postgresql server.

The postgresql connection url is decribed at:
http://www.postgresql.org/docs/7.4/static/jdbc-use.html#JDBC-CONNECT.

For example: jdbc:postgresql://host:port/database (host defaults to localhost, port defaults to 5432).

A quick bit of code to test your connectivity would be something like:


Class.forName("org.postgresql.Driver");
Connection c = DriverManager.getConnection("jdbc:postgresql:dbname", "username", "password"); 
System.out.println("Connected OK");    
c.close();